package io.github.junxworks.qt.modules.data.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import io.github.junxworks.ep.core.orm.BaseMapper;
import io.github.junxworks.qt.config.ds.Sharding;
import io.github.junxworks.qt.modules.data.entity.DStockMoneyflowMonthly;
import io.github.junxworks.qt.modules.data.entity.DStockStatMarketIndicator;

/**
 * @program :springbootdev
 * @description:
 * @author:Junxworks
 * @create:2019-08-17 15:03
 */
@Sharding
public interface MarketStatMapper extends BaseMapper {
	List<DStockStatMarketIndicator> statMarketConceptIndicatorsByDate(@Param("date") String date, @Param("market") String market);

	List<DStockStatMarketIndicator> statMarketIndexClassifyIndicatorsByDate(@Param("date") String date, @Param("market") String market);

	@Delete("delete from d_stock_stat_market_indicator where market=#{market} and trade_date=#{date}")
	int deleteMarketIndicatorDataByDate(@Param("date") String date, @Param("market") String market);
	
	@Delete("delete from d_stock_moneyflow_monthly where trade_mon=#{mon}")
	int deleteMoneyFlowMonthLy(@Param("mon")String month);
	
	@Select("""
			select 
			ts_code,
			date_format(trade_date,'%Y-%m') `trade_mon`,
			#{endDate} `end_date`,
			sum(buy_sm_amount) `buy_sm_amount`,
			sum(sell_sm_amount) `sell_sm_amount`,
			sum(buy_md_amount) `buy_md_amount`,
			sum(sell_md_amount) `sell_md_amount`,
			sum(buy_lg_amount) `buy_lg_amount`,
			sum(sell_lg_amount) `sell_lg_amount`,
			sum(buy_elg_amount) `buy_elg_amount`,
			sum(sell_elg_amount) `sell_elg_amount`
			from d_stock_moneyflow
			where trade_date >= #{startDate}
			and trade_date <= #{endDate}
			group by ts_code,trade_mon
			""")
	List<DStockMoneyflowMonthly> statMoneyFlowByMonth(@Param("startDate")String startDate,@Param("endDate")String endDate);
}
